package cn.ll.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ll.po.Cuscontact;
import cn.ll.service.CuscontactService;

public class CuscontactAction extends Action {
	/**
	 * 存储客户联系人
	 * @param request
	 * @param response
	 */
	public void save(HttpServletRequest request,HttpServletResponse response){
		String name = request.getParameter("name");
		String customerid = request.getParameter("customerid");
		String customername = request.getParameter("customername");
		String duty = request.getParameter("duty");
		String email = request.getParameter("email");
		String phone = request.getParameter("phone");
		String mobile = request.getParameter("mobile");
		String age = request.getParameter("age");
		String gender = request.getParameter("gender");
		String personality = request.getParameter("personality");
		String remark  = request.getParameter("remark");
		
		Cuscontact cuscontact = new Cuscontact();
		cuscontact.setName(name);
		cuscontact.setCustomerid(customerid);
		cuscontact.setCustomername(customername);
		cuscontact.setDuty(duty);
		cuscontact.setEmail(email);
		cuscontact.setPhone(phone);
		cuscontact.setMobile(mobile);
		cuscontact.setAge(Integer.parseInt(age));
		cuscontact.setGender(Integer.parseInt(gender));
		cuscontact.setPersonality(personality);
		cuscontact.setRemark(remark);
		
		CuscontactService cuscontactService = (CuscontactService) this.getApplicationContext().getBean("cuscontactService");
		cuscontactService.save(cuscontact);
		Map map = new HashMap(0);
		map.put("success", true);
		List list = new ArrayList();
		list.add(map);
		rtn(list, request, response);
		return;
	}
	
	/**
	 * 获得所有的客户联系人
	 * @return
	 */
	public void findAll(HttpServletRequest request,HttpServletResponse response){
		CuscontactService cuscontactService = (CuscontactService) this.getApplicationContext().getBean("cuscontactService");
		List<Cuscontact> list = cuscontactService.findAll();
		Map map = new HashMap(0);
		map.put("success", true);
		map.put("items", list);
		List list_send = new ArrayList();
		list_send.add(map);
		rtn(list_send, request, response);
		return ;
	}
}
